namespace 第四次作业
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void mergeBtn_Click(object sender, EventArgs e)
        {
            // 打开第一个文件
            OpenFileDialog openFileDlg1 = new OpenFileDialog();
            if (openFileDlg1.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string file1 = openFileDlg1.FileName;

            // 打开第二个文件
            OpenFileDialog openFileDlg2 = new OpenFileDialog();
            if (openFileDlg2.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string file2 = openFileDlg2.FileName;

            string outputDir = Path.Combine(Application.StartupPath, "Data");
            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }
            string outputFile = Path.Combine(outputDir, "merged.txt");

            using (StreamWriter writer = new StreamWriter(outputFile))
            {
                // 读取文件内容并写入到输出文件
                using (StreamReader reader = new StreamReader(file1))
                {
                    writer.Write(reader.ReadToEnd());
                }
                using (StreamReader reader = new StreamReader(file2))
                {
                    writer.Write(reader.ReadToEnd());
                }
            }

            MessageBox.Show("合并完成！");
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}